package com.sunshine.lnuplusweb.service.Impl;

import com.sunshine.lnuplusweb.dao.LessonMapper;
import com.sunshine.lnuplusweb.entities.Lesson;
import com.sunshine.lnuplusweb.service.LessonService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class LessonServiceImpl implements LessonService {

    @Resource
    private LessonMapper lessonMapper;

    /**
     * 插入课程到数据库
     * @param lessonList    课程列表
     */
    @Override
    public void insertSchedule(List<Lesson> lessonList) {
        for (Lesson lesson : lessonList) {
//            lessonMapper.insertLesson(
//                    lesson.getScheduleId(),
//                    lesson.getLessonId(),
//                    lesson.getDayOfWeek(),
//                    lesson.getStart(),
//                    lesson.getStartTime(),
//                    lesson.getEnd(),
//                    lesson.getEndTime(),
//                    lesson.getLessonName(),
//                    lesson.getTeacher(),
//                    lesson.getLocation(),
//                    lesson.getWeeks(),
//                    lesson.getColor()
//            );
            lessonMapper.insertLesson(lesson);
        }
    }

    @Override
    public void insertLesson(Lesson lesson) {
        lessonMapper.insertLesson(lesson);
    }

    /**
     * 通过课表ID删除课程，就是删除一个用户的课程，用于全部删除或者重新导入了课程
     * @param scheduleId        课表ID
     */
    @Override
    public void deleteLessonByScheduleId(int scheduleId) {
        lessonMapper.deleteLessonByScheduleId(scheduleId);
    }

    @Override
    public void deleteLesson(int scheduleId, String lessonId, int start, int end) {
        lessonMapper.deleteLesson(scheduleId, lessonId, start, end);
    }

    /**
     * 通过课表ID获取所有课程，用于查找某课表中所有课程
     * @param scheduleId        课表ID
     * @return                  课程列表
     */
    @Override
    public List<Lesson> getAllLessonByScheduleId(int scheduleId) {
        return lessonMapper.getUserAllLesson(scheduleId);
    }
}
